package com.cby.operation.anti.ui

import android.app.Activity
import android.os.Bundle
import com.cby.operation.anti.js.RealNameJsInterface
import com.cby.operation.common.ui.BaseDialogFragment
import com.cby.operation.common.ui.BaseWebDialogFragment
import com.cby.operation.sdk.*

/**
 * 实名认证的web页面
 */
class RealNameDialogFragment : BaseWebDialogFragment() {

    private lateinit var gameId: String
    private lateinit var uid: String
    private lateinit var type: String
    private lateinit var token: String

    companion object{

        private const val KEY_UID = "uid"
        private const val KEY_TYPE = "type"
        private const val KEY_TOKEN = "token"

        fun show(activity: Activity, uid: String, type: String, token: String) : BaseDialogFragment {
            val fragment = RealNameDialogFragment()
            val data = Bundle()
            data.putString(KEY_UID, uid)
            data.putString(KEY_TYPE, type)
            data.putString(KEY_TOKEN, token)
            fragment.arguments = data
            fragment.show(activity.fragmentManager, TAG_FRAGMENT_REAL_NAME)

            return fragment
        }
    }

    override fun parseArgs() {
        gameId = SdkConfiguration.gameId
        uid = arguments.getString(KEY_UID).toString()
        type = arguments.getString(KEY_TYPE).toString()
        token = arguments.getString(KEY_TOKEN).toString()

    }


    override fun setWebContent() {
        val jsInterface = RealNameJsInterface(activity)
        webView.addJavascriptInterface(jsInterface, JS_INTERFACE_NAME)
        val url: String = getWebRealNameUrl(SdkConfiguration.orientation, gameId, uid, type, token)
        webView.loadUrl(url)
    }
}